﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace DAO
{
    public class MonAnDAO : DataProvider
    {
        public ArrayList GetDSMonAn()
        {
            connect();
            string sql = "select * from MonAn";
            adapter = new SqlDataAdapter(sql, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);
            disconnect();
            return arr;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            MonAnDTO maDTO = new MonAnDTO();
            maDTO.MONANID = int.Parse(dt.Rows[i][0].ToString());
            maDTO.TENMONAN = dt.Rows[i][1].ToString();

            return (object)maDTO;
        }
        public ArrayList TimKiem(string tukhoa)
        {
            connect();
            string sql = "select * from MonAn where ten_mon_an like '%" + tukhoa + "%' ";
            adapter = new SqlDataAdapter(sql, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);
            disconnect();
            return arr;
        }
    }
}
